From 1e7f68e29e843f2f189310d9f0bedbde234b6573 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Thu, 11 Dec 2014 21:45:39 +0100
Subject: [PATCH] Record command history and register after command.

The command to run was written to history and ':' register right before it was
run. This caused :register to show always the register command as last ex
command. Now the command is written to history and register after attempt to
run it.
---
 src/ex.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/ex.c b/src/ex.c
index 1290df2..e207c13 100644
--- a/src/ex.c
+++ b/src/ex.c
@@ -475,20 +475,23 @@ static void input_activate(void)
 
 VbCmdResult ex_run_string(const char *input)
 {
+    /* copy to have original command for history */
+    const char *in  = input;
     VbCmdResult res = VB_CMD_ERROR;
     ExArg *arg = g_slice_new0(ExArg);
     arg->lhs   = g_string_new("");
     arg->rhs   = g_string_new("");
 
-    vb_register_add(':', input);
-    history_add(HISTORY_COMMAND, input, NULL);
-
-    while (input && *input) {
-        if (!parse(&input, arg) || !(res = execute(arg))) {
-            free_cmdarg(arg);
-            return VB_CMD_ERROR | VB_CMD_KEEPINPUT;
+    while (in && *in) {
+        if (!parse(&in, arg) || !(res = execute(arg))) {
+            res = VB_CMD_ERROR | VB_CMD_KEEPINPUT;
+            break;
         }
     }
+
+    history_add(HISTORY_COMMAND, input, NULL);
+    vb_register_add(':', input);
+
     free_cmdarg(arg);
 
     return res;
-- 
2.20.1